package com.zoiz.base.model;
import java.util.List;
import java.util.ArrayList;
import com.zoiz.plus.extend.StringUtils;
import com.zoiz.dbutils.QueryHelper;
import com.zoiz.dbutils.QueryHelper.WrappedStatement;
import com.zoiz.util.PageBean;
/**
 * admin_menu
 * 
 * @author chenjiankang
 * 
 */
public class Admin_menu extends com.zoiz.dbutils.Model{
	private static final long serialVersionUID = 1L;
		/** id **/ 
	private java.lang.Long id=null;
		/** actionurl **/ 
	private java.lang.String actionurl=null;
		/** showorder **/ 
	private java.lang.Integer showorder=null;
		/** 1-菜单 2-功能 **/ 
	private java.lang.Integer type=null;
		/** rgt **/ 
	private java.lang.Long rgt=null;
		/** lft **/ 
	private java.lang.Long lft=null;
		/** title **/ 
	private java.lang.String title=null;
		/** parentid **/ 
	private java.lang.Long parentid=null;
	/**
	 * build insert sql string
	 */
	WrappedStatement _getInsertWS() {
		List<Object> values = new ArrayList<Object>();
		StringBuilder insertSql = new StringBuilder();
		insertSql.append("INSERT INTO ADMIN_MENU(");
		if(id!=null){
			insertSql.append("ID,");
			values.add(id);
		}
		if(StringUtils.isNotBlank(actionurl)){
			insertSql.append("ACTIONURL,");
			values.add(actionurl);
		}
		if(showorder!=null){
			insertSql.append("SHOWORDER,");
			values.add(showorder);
		}
		if(type!=null){
			insertSql.append("TYPE,");
			values.add(type);
		}
		if(rgt!=null){
			insertSql.append("RGT,");
			values.add(rgt);
		}
		if(lft!=null){
			insertSql.append("LFT,");
			values.add(lft);
		}
		if(StringUtils.isNotBlank(title)){
			insertSql.append("TITLE,");
			values.add(title);
		}
		if(parentid!=null){
			insertSql.append("PARENTID,");
			values.add(parentid);
		}
		insertSql.deleteCharAt(insertSql.length()-1);
		insertSql.append(") VALUES (");
		for(int i=0;i<values.size();i++){
			insertSql.append("?,");
		}
		insertSql.deleteCharAt(insertSql.length()-1).append(")");
		return new QueryHelper.WrappedStatement(insertSql.toString(),values);
	}
/**
	 * build update sql string
	 */
	WrappedStatement _getUpdateWS() {
		List<Object> values = new ArrayList<Object>();
		StringBuilder updateSql = new StringBuilder();
		updateSql.append("UPDATE ADMIN_MENU SET ");
		if(StringUtils.isNotBlank(actionurl)){
			updateSql.append("ACTIONURL=?,");
			values.add(actionurl);
		}
		if(showorder!=null){
			updateSql.append("SHOWORDER=?,");
			values.add(showorder);
		}
		if(type!=null){
			updateSql.append("TYPE=?,");
			values.add(type);
		}
		if(rgt!=null){
			updateSql.append("RGT=?,");
			values.add(rgt);
		}
		if(lft!=null){
			updateSql.append("LFT=?,");
			values.add(lft);
		}
		if(StringUtils.isNotBlank(title)){
			updateSql.append("TITLE=?,");
			values.add(title);
		}
		if(parentid!=null){
			updateSql.append("PARENTID=?,");
			values.add(parentid);
		}
		updateSql.deleteCharAt(updateSql.length()-1);
		updateSql.append(" WHERE ID = ?");
		values.add(id);
		return new QueryHelper.WrappedStatement(updateSql.toString(),values);
	}
	
		public java.lang.Long getId() {
		return this.id;
	}
	public void setId(java.lang.Long id ) {
		this.id=id;
	}
		public java.lang.String getActionurl() {
		return this.actionurl;
	}
	public void setActionurl(java.lang.String actionurl ) {
		this.actionurl=actionurl;
	}
		public java.lang.Integer getShoworder() {
		return this.showorder;
	}
	public void setShoworder(java.lang.Integer showorder ) {
		this.showorder=showorder;
	}
		public java.lang.Integer getType() {
		return this.type;
	}
	public void setType(java.lang.Integer type ) {
		this.type=type;
	}
		public java.lang.Long getRgt() {
		return this.rgt;
	}
	public void setRgt(java.lang.Long rgt ) {
		this.rgt=rgt;
	}
		public java.lang.Long getLft() {
		return this.lft;
	}
	public void setLft(java.lang.Long lft ) {
		this.lft=lft;
	}
		public java.lang.String getTitle() {
		return this.title;
	}
	public void setTitle(java.lang.String title ) {
		this.title=title;
	}
		public java.lang.Long getParentid() {
		return this.parentid;
	}
	public void setParentid(java.lang.Long parentid ) {
		this.parentid=parentid;
	}
		/**
	 * find Admin_menu by id
	 */	
	 public static Admin_menu findOneById(Object id){
	 	return findById(Admin_menu.class,id);
	 }
	 public static Admin_menu findOneBy(String query,Object... params){
	 	return findOneBy(Admin_menu.class, query, params);
	 }
	/**
	 * save or update Admin_menu
	 */
	 public Admin_menu save(){
	 	if(getId()==null){
	 		Long _id = insert(_getInsertWS());
	 		return Admin_menu.findOneById(_id);
	 	}else{
	 		update(_getUpdateWS());
	 		return Admin_menu.findOneById(this.id);
	 	}
	 }
	 /**
     * Count Admin_menus
     * @return number of entities of this class
     */
    public static long count() {
    	return count(Admin_menu.class);
    }
	// count by
	public static Long count(String query, Object... params) {
		return count(Admin_menu.class,query,params);
	}
    /**
     * Find all Admin_menus of this type
     */
    public static List<Admin_menu> findAll() {
        return findAllBy(Admin_menu.class,null);
    }
    
    public static List<Admin_menu> findAllBy(String query, Object... params) {
        return findAllBy(Admin_menu.class,query,params);
    }
    
    public static int deleteById(Object id){
    	return deleteById(Admin_menu.class,id);
    }
    public static int deleteBy(String query,Object... params){
    	return deleteBy(Admin_menu.class,query,params);
    }
    public static PageBean findBy(String query,int from,int count,Object... params){
    	List models = QueryHelper.query_slice(Admin_menu.class,query,from,count,params);
    	Long total = Admin_menu.count(query,params);
    	PageBean pb = new PageBean(from,count,total.intValue());
    	pb.setModel(models);
    	return pb;
    }
    
}